<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>去掉空格</title>
	<style>
		p{
			background-color: #ccc;
			display: inline;
		}
	</style>
</head>
<body>
	输入框：<input type="text"><br>
	<span style="color: red;font-size: 30px;">空格去除后：</span>
	<p style="font-size: 50px;font-weight: 800;" ></p>
	<script>
		var input=document.querySelector("input");
		var p=document.querySelector("p");
		input.onchange=function(){
			var val=this.value;
			p.innerHTML=val.replace(/(^\s*)|(\s*$)/g,"");
		}
	</script>
</body>
</html>